home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / controls / dynacntr.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-05-16  |  2.7 KB  |  90 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Dynamic Controls"
  4.    ClientHeight    =   4020
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   7365
  8.    Height          =   4425
  9.    Left            =   1035
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4020
  13.    ScaleWidth      =   7365
  14.    Top             =   1140
  15.    Width           =   7485
  16.    Begin CommandButton Command3 
  17.       Caption         =   "End"
  18.       Height          =   495
  19.       Left            =   5880
  20.       TabIndex        =   3
  21.       Top             =   240
  22.       Width           =   1215
  23.    End
  24.    Begin TextBox Text1 
  25.       Height          =   855
  26.       Index           =   0
  27.       Left            =   240
  28.       TabIndex        =   0
  29.       Text            =   "Text1"
  30.       Top             =   240
  31.       Width           =   1455
  32.    End
  33.    Begin CommandButton Command1 
  34.       Caption         =   "Add Text Box"
  35.       Height          =   375
  36.       Left            =   240
  37.       TabIndex        =   1
  38.       Top             =   2640
  39.       Width           =   1575
  40.    End
  41.    Begin CommandButton Command2 
  42.       Caption         =   "Delete Text Box"
  43.       Enabled         =   0   'False
  44.       Height          =   375
  45.       Left            =   240
  46.       TabIndex        =   2
  47.       Top             =   3120
  48.       Width           =   1575
  49.    End
  50. Option Explicit
  51. Dim TextBoxCount As Integer
  52. Dim RepeatFactor As Integer
  53. Sub Command1_Click ()
  54.     Dim myRed As Integer, myBlue As Integer, myGreen As Integer
  55.     myRed = Rnd * 255
  56.     myGreen = Rnd * 255
  57.     myBlue = Rnd * 255
  58.     'Get the next array index number
  59.     TextBoxCount = TextBoxCount + 1
  60.     'Create the new control dynamically
  61.     Load text1(TextBoxCount)
  62.     'Set the position for top left corner of the new control
  63.     'so it won't fall on top of previous control
  64.     If text1(TextBoxCount - 1).Top > .7 * form1.Height Then
  65.         text1(TextBoxCount).Move text1(0).Left + RepeatFactor * 1600, text1(0).Top
  66.         RepeatFactor = RepeatFactor + 1
  67.     Else
  68.         text1(TextBoxCount).Move text1(TextBoxCount - 1).Left + 200, text1(TextBoxCount - 1).Top + 200
  69.     End If
  70.     'Give it a random color
  71.     text1(TextBoxCount).BackColor = RGB(myRed, myGreen, myBlue)
  72.     'Now, display the new control
  73.     text1(TextBoxCount).Visible = True
  74.     command2.Enabled = True
  75. End Sub
  76. Sub Command2_Click ()
  77.     Unload text1(TextBoxCount)
  78.     TextBoxCount = TextBoxCount - 1
  79.     If TextBoxCount = 0 Then
  80.         command2.Enabled = False
  81.     End If
  82. End Sub
  83. Sub Command3_Click ()
  84.     End
  85. End Sub
  86. Sub Form_Load ()
  87.     Randomize Timer
  88.     RepeatFactor = 1
  89. End Sub
  90.